﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DatabaseAccessLayer;

namespace WebApplication
{
    public partial class Membership_Step2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                List<PropertyTypes> lst = PropertyMgmt.GetPropertyTypes();
                var residential = from list in lst
                                  where list.PropertyID == 1
                                  select list;

                chkResidential.DataSource = residential;
                chkResidential.DataTextField = "Name";
                chkResidential.DataValueField = "ID";
                chkResidential.DataBind();

                var commercial = from list in lst
                                  where list.PropertyID == 2
                                  select list;
                chkCommercial.DataSource = commercial;
                chkCommercial.DataTextField = "Name";
                chkCommercial.DataValueField = "ID";
                chkCommercial.DataBind();

                List<PropertyTypes> lst1 = PropertyMgmt.GetPropertyTypesMgmt();
                var residentialmgmt = from list in lst1
                                  where list.PropertyID == 1
                                  select list;

                chkResidentialMgmt.DataSource = residentialmgmt;
                chkResidentialMgmt.DataTextField = "Name";
                chkResidentialMgmt.DataValueField = "ID";
                chkResidentialMgmt.DataBind();

                var commercialmgmt = from list in lst1
                                 where list.PropertyID == 2
                                 select list;
                chkCommercialMgmt.DataSource = commercialmgmt;
                chkCommercialMgmt.DataTextField = "Name";
                chkCommercialMgmt.DataValueField = "ID";
                chkCommercialMgmt.DataBind();
            }
            ((System.Web.UI.HtmlControls.HtmlGenericControl)Master.FindControl("divbreadcrum")).InnerHtml = @"<a href='default.aspx'>Home</a> > <a href='Sign-In.aspx'>Sign In</a> > <a href='Membership.aspx'>New Registration</a> > <span>Membership</span>";
        }
        public void btnSubmit_Click(object sender, EventArgs e)
        {
            string Residential ="" ;
            string Commercial ="" ;
            string Residentialmgmt = "";
            string Commercialmgmt = "";
            int UserID =Convert.ToInt32(Request.QueryString["ID"]);
            if(UserID !=null)
            {
            foreach (ListItem item in chkResidential.Items)
            {
                if (item.Selected)
                {
                    Residential = Residential + item.Value+","; 
                }
            }

            foreach (ListItem item in chkCommercial.Items)
            {
                if (item.Selected)
                {
                    Commercial = Commercial + item.Value + ",";
                }
            }
            foreach (ListItem item in chkResidentialMgmt.Items)
            {
                if (item.Selected)
                {
                    Residentialmgmt = Residentialmgmt + item.Value + ",";
                }
            }
            foreach (ListItem item in chkCommercialMgmt.Items)
            {
                if (item.Selected)
                {
                    Commercialmgmt = Commercialmgmt + item.Value + ",";
                }
            }
            string IsCounsultant = "";
            if(chkResidentailConsultant.Checked)
            {
                IsCounsultant = chkResidentailConsultant.Text;
            }
            string Experience = txtExperience.Text.Trim();
            string licence = txtLicenseNumber.Text.Trim();
            string desc = txtDescription.Text.Trim();

            int Result = clsUser.MemberShipUserSetp2(UserID, Residential, Commercial, Residentialmgmt, Commercialmgmt,IsCounsultant, Experience, licence, desc);
            if (Result>0)
            {
                Response.Redirect("Membership-Complete.aspx?ID=" + UserID);
            }

            }

        }
     
    }
}